home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <stdlib.h>
- #include <ctype.h>
- #include "defs.h"
- #ifdef TOWNS
- #include <egb.h>
- #include <fmc.h>
- #include "rsb.h"
- #endif
-
- #define MENU_MAX 11
- #define M_SJIS 0
- #define M_EUC 1
- #define M_JIS 2
-
- extern UCHAR *cvram;
- extern char *SPCSTR;
- extern int Line_no;
- extern short ReWrt_flg;
- extern int TrmCol;
- extern int DspCnt;
-
- extern char *kanji_chk();
- extern BOOL Input();
- extern void Dmy_form();
- extern void wrtstr();
- extern void Soft_Timer();
- extern int kbhit();
- extern int Get_key();
- extern void gtime();
- extern void BakPut();
- extern void Dsp_vram();
- extern int Sel_menu();
- extern void Dsp_free();
- extern int strlen();
- extern void strcpy();
- extern void Dsp_vram_flash();
- extern void BP_Term_ENQ();
- extern void BP_DLE_Seen();
- extern void ins_chr();
- extern void Set_vram();
- extern void Del_buf();
- extern void Cur_btm_file();
- extern int File_sel();
- extern void Cut_buf();
- extern int Undo_cpy();
- extern void memset();
- extern int Con_init();
- extern void CD_menu();
- extern void Con_end();
- extern void Dsp_PFKEY();
-
- int port=0,bps=0x05;
- static int mode=0x11,brk=0,swait=0,KanMod=0;
- static int Down_flg=FALSE,Line_flg=FALSE,Line_X=0;
- static FILE *Down_fp=NULL;
- static int Flaing=FALSE;
- static unsigned brktime[]={ 25,50,100,200 };
- static int swtime[]={1,5000,10000,20000,50000 };
- static RSB_PARA para;
-
- #include "xmodem.c"
-
- #ifdef TOWNS
- void Test_RSB_mode()
- {
- static short flg=FALSE;
-
- if ( flg != FALSE )
- return;
-
- flg = TRUE;
- RSB_rdpara(port,(char *)¶);
- mode = para.mode; /* 通信モード */
- bps = para.baud; /* ボーレート */
- }
- int RSB_init(pt,md,bp)
- int pt,md,bp;
- {
- int er;
-
- para.mode = md; /* 通信モード */
- para.baud = bp; /* ボーレート */
- para.rbuf = 0; /* 受信バッファアドレス */
- para.stime = 500; /* 送信タイムアウト */
- para.rtime = 500; /* 受信タイムアウト */
- para.rinfbuf = 0; /* 受信通知アドレス */
- para.extmode = 0; /* 拡張モード */
- para.xon = 0x11; /* XONコード */
- para.xoff = 0x13; /* XOFFコード */
-
- RSB_dtr(pt,1); /* DTR信号の保持 */
- RSB_close(pt);
- if ( (er = RSB_setpara(pt,(char *)¶)) == 0 )
- er = RSB_open(pt);
- return er;
- }
- #endif
-
- /*********************************************************
- 012345678901234567890123456789012345678901234567890123
- 1 2 3 4 5
- * * * * * * *
- ポ-トNo. 0 1 2 3 4
- 速 度 300 600 1200 2400 4800 9600 19200
- ビット長 7ビット 8ビット
- パリティ- 無し 偶数 奇数
- ストップビット 1ビット 2ビット
- フロ-制御 無し XON/OFF
- ブレ-ク時間 250ms 500ms 1sec 2sec
- 文字色 青色 赤色 紫色 緑色 水色 黄色 白色
- 文字制御 有り 無し 表示
- 改行待ち 無し 50ms 100ms 200ms 500ms
- 漢字コ-ド SJIS EUC JIS
- **********************************************************/
- void Set_RSB_mode(x,y)
- int x,y;
- {
- unsigned int ec;
- int i,n,no,ch,cl,fg;
- char tmp[160];
- static int pt,bp,bit,party,stop,xfls,br,col,ctl,swt,km;
- static struct {
- int *flg_mn;
- int max_mn;
- char *ttl_mn;
- char *sub_mn[8];
- } MODE_menu[]={
- { &pt,5,"ポ-トNo. ","0","1","2","3","4" },
- { &bp,7,"速 度 ","300","600","1200","2400","4800","9600","19200"},
- { &bit,2,"ビット長 ","7ビット","8ビット" },
- { &party,3,"パリティ- ","なし","奇数","偶数" },
- { &stop,2,"ストップビット ","1ビット","2ビット" },
- { &xfls,2,"フロ-制御 ","なし","あり" },
- { &br,4,"ブレ-ク時間 ","250ms","500ms","1sec","2sec" },
- { &col,7,"文字色 ","青色","赤色","紫色","緑色","水色","黄色","白色" },
- { &ctl,3,"文字制御 ","有り","無し","表示" },
- { &swt,5,"改行WAIT ","無し","50ms","100ms","200ms","500ms" },
- { &km, 2,"漢字コ-ト ","SJIS","EUC","JIS" }
- };
-
- pt = port;
- bp = bps;
- bit = ((mode & 0x01) == 0 ? 0 : 1);
- party = ((mode & 0x02) == 0 ? 0 : ((mode & 0x04) == 0 ? 1 : 2));
- stop = ((mode & 0x08) == 0 ? 0 : 1);
- xfls = ((mode & 0x10) == 0 ? 0 : 1);
- br = brk;
- col = TrmCol-1;
- ctl = DspCnt;
- swt = swait;
- km = KanMod;
-
- Dmy_form(tmp,54,0x98,0x95,0x99);
- wrtstr(tmp,x,y,0x07);
- Dmy_form(tmp,54,0x96,0x20,0x96);
- for ( i = 0 ; i < MENU_MAX ; i++ )
- wrtstr(tmp,x,y+i+1,0x07);
- Dmy_form(tmp,54,0x9A,0x95,0x9B);
- wrtstr(tmp,x,y+MENU_MAX+1,0x07);
- x += 2; y += 1;
-
- for ( fg = FALSE,no = 0 ; fg == FALSE ; ) {
- for ( i = 0 ; i < MENU_MAX ; i++ ) {
- if ( i == no ) cl = 0x14; else cl = 0x07;
- wrtstr(MODE_menu[i].ttl_mn,x,y+i,cl);
- for ( n = 0 ; n < MODE_menu[i].max_mn ; n++ ) {
- if ( n == *(MODE_menu[i].flg_mn) ) cl = 0x14; else cl = 0x07;
- wrtstr(MODE_menu[i].sub_mn[n],x+11+n*6,y+i,cl);
- }
- }
- ch = Get_key(&ec);
- if ( ch == '\x1B' || ec == 0x7200 )
- goto ENDOF;
- else if ( ch == '\x0D' || ec == 0x7300 )
- break;
- else if ( ch == ' ' || ch == '\x1F' ) {
- if ( ++no >= MENU_MAX )
- no = 0;
- } else if ( ch == '\x08' || ch == '\x1E' ) {
- if ( --no < 0 )
- no = MENU_MAX-1;
- } else if ( ch == '\x1C' ) {
- *(MODE_menu[no].flg_mn) += 1;
- if ( *(MODE_menu[no].flg_mn) >= MODE_menu[no].max_mn )
- *(MODE_menu[no].flg_mn) = 0;
- } else if ( ch == '\x1D' ) {
- *(MODE_menu[no].flg_mn) -= 1;
- if ( *(MODE_menu[no].flg_mn) < 0 )
- *(MODE_menu[no].flg_mn) = MODE_menu[no].max_mn - 1;
- }
- }
- mode = 0;
- if ( bit != 0 ) mode |= 0x01;
- if ( party == 1 ) mode |= 0x02;
- if ( party == 2 ) mode |= 0x06;
- if ( stop != 0 ) mode |= 0x08;
- if ( xfls != 0 ) mode |= 0x10;
- if ( pt != port ) {
- RSB_close(port);
- port = pt;
- }
- bps = bp;
- brk = br;
- TrmCol = col+1;
- DspCnt = ctl;
- swait = swt;
- RSB_init(port,mode,bps);
- KanMod = km;
- ENDOF:
- #ifdef TOWNS
- Dsp_vram_flash();
- #endif
- Dsp_vram(cvram);
- Dsp_free();
- }
- int jis2sjis(chr)
- unsigned int chr;
- {
- int hi,lo;
-
- hi=(chr >> 8)&0xff;
- lo=chr & 0xff;
- if ( (hi & 1) != 0 )
- lo += 0x1F;
- else
- lo += 0x7D;
- if ( lo >= 0x7F )
- lo++;
- hi = (hi - 0x21 >> 1) + 0x81;
- if ( hi > 0x9F )
- hi += 0x40;
- return (hi << 8 | lo);
- }
- int sjis2jis(chr)
- unsigned int chr;
- {
- int hi,lo;
-
- hi=(chr >> 8)&0xff;
- lo=chr & 0xff;
- hi -= ( hi <= 0x9f) ? 0x71 : 0xb1;
- hi = hi * 2 +1;
- if ( lo > 0x7f )
- lo--;
- if ( lo >= 0x9e ) {
- lo -= 0x7d;
- hi++;
- }
- else
- lo -= 0x1f;
- return (hi << 8 | lo);
- }
- void recv_chk()
- {
- int x,y,i,bl,len,ch;
- unsigned int st;
- static int EucFlg=0,bch=0;
- static char tmp[1024];
-
- RSB_read(port,&len);
- if ( len <= 0 )
- return;
- if ( len > 1024 ) len = 1024;
- for ( bl = i = 0 ; i < len ; i++ ) {
- if ( EucFlg != 2 )
- RSB_receive(port,&ch,&st);
- if ( ch == 0x05 ) { /* ENQ Then B Plus Protocol Start ? */
- BP_Term_ENQ();
- break;
- }
- if ( ch == 0x10 ) { /* DLE Then B Plus Protocol Start ? */
- BP_DLE_Seen();
- break;
- }
-
- switch(KanMod) {
- case M_EUC:
- switch(EucFlg) {
- case 0:
- if ( (ch & 0x80) != 0 ) {
- bch = ch;
- EucFlg = 1;
- continue;
- }
- break;
- case 1:
- if ( (ch & 0x80) != 0 ) {
- ch = ((bch << 8) | ch) & 0x7F7F;
- ch = jis2sjis(ch);
- bch = ch & 0xFF;
- ch >>= 8;
- } else {
- x = ch;
- ch = bch;
- bch = x;
- }
- EucFlg = 2;
- break;
- case 2:
- ch = bch;
- EucFlg = 0;
- break;
- }
- break;
- }
-
- BakPut(ch);
- if ( ch != '\0' && ch != '\x0D' ) {
- if ( ch == '\x0A' )
- tmp[bl++] = 0x0D;
- tmp[bl++] = ch;
- }
- if ( Down_fp != NULL && ch != '\x08' && ch != '\0' )
- fputc(ch,Down_fp);
- }
- Dsp_vram(cvram);
- if ( Down_flg != FALSE ) {
- x = Cur_X; y = Cur_Y;
- ins_chr(tmp,bl);
- Set_vram();
- Dsp_free();
- Cur_X = x; Cur_Y = y;
- }
- }
- void Send_char(ch)
- int ch;
- {
- unsigned st;
- static int BakKan='\0';
- static int SftIn=FALSE;
-
- ch &= 0xff;
- switch(KanMod) {
- case M_SJIS: /* SJIS */
- RSB_send(port,ch,&st);
- break;
- case M_JIS: /* JIS */
- if ( BakKan != '\0' ) {
- if ( iskanji2(ch) ) {
- ch = sjis2jis((BakKan << 8) | ch);
- if ( SftIn == FALSE ) {
- RSB_send(port,0x1b,&st);
- RSB_send(port,'$',&st);
- RSB_send(port,'B',&st);
- SftIn=TRUE;
- }
- RSB_send(port,ch >> 8,&st);
- RSB_send(port,ch & 0xff,&st);
- BakKan = '\0';
- return;
- }
- RSB_send(port,BakKan,&st);
- RSB_send(port,ch,&st);
- BakKan = '\0';
- } else if ( iskanji(ch) ) {
- BakKan = ch;
- return;
- } else {
- if ( SftIn != FALSE ) {
- RSB_send(port,0x1b,&st);
- RSB_send(port,'(',&st);
- RSB_send(port,'J',&st);
- SftIn=FALSE;
- }
- RSB_send(port,ch,&st);
- }
- break;
- case M_EUC: /* EUC */
- if ( BakKan != '\0' ) {
- if ( iskanji2(ch) ) {
- ch = sjis2jis((BakKan << 8) | ch) | 0x8080;
- RSB_send(port,ch >> 8,&st);
- RSB_send(port,ch & 0xff,&st);
- BakKan = '\0';
- return;
- }
- RSB_send(port,BakKan,&st);
- RSB_send(port,ch,&st);
- BakKan = '\0';
- } else if ( iskanji(ch) ) {
- BakKan = ch;
- return;
- } else
- RSB_send(port,ch,&st);
- break;
- }
- if ( ch == 0x0D && swait != 0 )
- Soft_Timer(swtime[swait]);
- }
- void Dsp_RSBKEY()
- {
- int i;
- static char *menu[]={
- " 設定 "," 入力 "," AUTO "," ","CD演奏",
- "ダウン","アップ"," ブレ-ク"," 終了 "," 中断 " };
-
- for ( i = 0 ; i < 10 ; i++ )
- wrtstr(menu[i],i*7+(i/5),MENU_Y,0x16);
- }
- void Down_load()
- {
- int x,y;
- char tmp[80];
- static int no=ERR;
- static char *menu[]={
- "1 編集バッファに (新規) ",
- "2 編集バッファに (追加) ",
- "",
- "3 ファイルに(新規/追加) ",
- "",
- "4 X-Modemでダウンする ",
- "5 X-Modemでダウン(高速) ",
- NULL };
-
- wrtstr(SPCSTR,30,1,0x1F);
- if ( Down_flg != FALSE || Down_fp != NULL ) {
- if ( Down_fp != NULL ) {
- fputc('\x1A',Down_fp);
- fclose(Down_fp);
- Down_fp = NULL;
- }
- Down_flg = FALSE;
- wrtstr(" ",32,0,0x1F);
- return;
- }
-
- if ( Sel_menu(menu,25,2,&no) != FALSE )
- goto ENDOF;
-
- if ( no == 0 ) {
- Del_buf(0l,btm_ptr);
- top_ptr = lin_ptr = ent_ptr = btm_ptr = 0;
- Line_no = 0;
- Down_flg = TRUE;
- } else if ( no == 1 ) {
- x = Cur_X; y = Cur_Y;
- Cur_btm_file();
- Cur_X = x; Cur_Y = y;
- Down_flg = TRUE;
- } else if ( no == 2 ) {
- tmp[0] = '\0';
- if ( Input(tmp,"ファイル名 ") != FALSE || File_sel(tmp) != FALSE )
- goto ENDOF;
- if ( (Down_fp = fopen(tmp,"ab+")) == NULL ) {
- wrtstr("(ファイルがオ-プン出来ません)",30,1,0x12);
- goto ENDOF;
- }
- } else if ( no == 3 || no == 4 ) {
- tmp[0] = '\0';
- if ( Input(tmp,"ファイル名 ") != FALSE || File_sel(tmp) != FALSE )
- goto ENDOF;
- Flaing = (no == 3 ? FALSE : TRUE);
- RSB_init(port,mode & 0xEF,bps);
- Down_Xmodem(tmp);
- RSB_init(port,mode,bps);
- goto ENDOF;
- }
- wrtstr("ダウンロ-ド実行中",32,0,0x15);
- ENDOF:
- Dsp_vram(cvram);
- Dsp_free();
- }
- void Up_load()
- {
- int ch,i,n,ct;
- unsigned int ec;
- FILE *fp;
- char tmp[256];
- char *p;
- LONG ptr,sz;
- static int no=ERR;
- static char *menu[]={
- "1 編集バッファをアップ ",
- "2 Undoバッファをアップ ",
- "",
- "3 ファイルをアップする ",
- "",
- "4 X-Modemでアップする ",
- NULL };
-
- wrtstr(SPCSTR,30,1,0x1F);
- if ( Sel_menu(menu,30,2,&no) != FALSE )
- goto ENDOF;
-
- if ( no == 0 ) {
- ptr = 0;
- sz = btm_ptr;
- n = i = 0;
- } else if ( no == 1 ) {
- ptr = 0;
- n = 0;
- } else if ( no == 2 ) {
- tmp[0] = '\0';
- if ( Input(tmp,"ファイル名 ") != FALSE || File_sel(tmp) != FALSE )
- goto ENDOF;
- if ( (fp = fopen(tmp,"rb")) == NULL ) {
- wrtstr("(ファイルがオ-プン出来ません)",30,1,0x12);
- goto ENDOF;
- }
- } else if ( no == 3 ) {
- tmp[0] = '\0';
- if ( Input(tmp,"ファイル名 ") != FALSE || File_sel(tmp) != FALSE )
- goto ENDOF;
- RSB_init(port,mode & 0xEF,bps);
- Up_Xmodem(tmp);
- RSB_init(port,mode,bps);
- goto ENDOF;
- }
-
- wrtstr("アップロ-ド実行中",32,1,0x14);
- Dsp_vram(cvram);
- for ( ct = 0 ; ; ct++ ) {
- if ( kbhit() != 0 ) {
- ch = Get_key(&ec);
- if ( ch == 0x1B || ec == 0x7200 )
- break;
- }
- if ( no == 0 ) {
- if ( i >= n ) {
- if ( sz <= 0 )
- break;
- if ( sz < 256 ) n = sz; else n = 256;
- Cut_buf(tmp,n,ptr);
- ptr += n;
- sz -= n;
- i = 0;
- }
- ch = tmp[i++];
- } else if ( no == 1 ) {
- if ( n <= 0 ) {
- if ( (n = Undo_cpy(tmp,256,ptr)) == 0 )
- break;
- p = tmp;
- ptr += n;
- }
- ch = *(p++); n--;
- } else if ( no == 2 ) {
- if ( (ch = fgetc(fp)) == EOF )
- break;
- }
- if ( ct > 50 ) {
- recv_chk();
- ct = 0;
- }
- if ( ch != '\x0A' && ch != '\x1A' )
- Send_char(ch & 0xff);
- }
- if ( no == 3 )
- fclose(fp);
- wrtstr(SPCSTR,30,1,0x1F);
- ENDOF:
- Dsp_vram(cvram);
- Dsp_free();
- }
- void RSB_end()
- {
- if ( cvram != NULL )
- RSB_close(port);
- wrtstr(" ",10,0,0x1F);
- free(cvram);
- cvram = NULL;
- }
- void Line_edit(ch)
- int ch;
- {
- int i;
- static char tmp[180];
-
- if ( Line_flg == FALSE ) {
- if ( ch != 0xFFFF )
- Send_char(ch & 0xff);
- if ( Line_X > 0 ) {
- Line_X = 0;
- memset(tmp,' ',80); tmp[80] = 0;
- wrtstr(tmp,0,MAX_Y2+OFF_Y,0);
- wrtstr(tmp,0,MAX_Y2+OFF_Y+1,0);
- }
- return;
- }
- if ( ch == 0x08 && Line_X > 0 ) {
- Line_X--;
- if ( &tmp[Line_X] != kanji_chk(tmp,Line_X) )
- Line_X--;
- } else if ( Line_X == 0 && ch < ' ' ) {
- Send_char(ch & 0xff);
- } else if ( ch != 0x08 && ch != 0x1B && ch != 0xFFFF )
- tmp[Line_X++] = ch;
- if ( Line_X >= 158 || ch == 0x0D || ch == 0x1B ) {
- for ( i = 0 ; i < Line_X ; i++ )
- Send_char(tmp[i] & 0xff);
- if ( Line_X >= 80 ) {
- memset(tmp,' ',80); tmp[80] = 0;
- wrtstr(tmp,0,MAX_Y2+OFF_Y+1,0);
- }
- Line_X = 0;
- }
- tmp[Line_X] = 0xFE; tmp[Line_X+1] = 0x1B;
- memset(tmp+Line_X+2,' ',164-Line_X);
- tmp[161] = 0;
- if ( Line_X < 80 )
- tmp[81] = '\0';
- wrtstr(tmp,0,MAX_Y2+OFF_Y,0x1D);
- ReWrt_flg = (-2);
- }
- void RSB_loop()
- {
- int ch,ef;
- int Bk_X,Bk_Y;
- unsigned ec;
-
- wrtstr(SPCSTR,30,1,0x1F);
- if ( cvram == NULL ) {
- Test_RSB_mode();
- RSB_init(port,mode,bps);
- }
- if ( Con_init() != FALSE ) {
- RSB_close(port);
- return;
- }
- wrtstr("通信",10,0,0x17);
- Dsp_RSBKEY();
-
- for ( ef = FALSE ; ef == FALSE ; ) {
- recv_chk();
- for ( ; ; ) {
- if ( Line_flg != FALSE ) {
- Bk_X = Cur_X; Bk_Y = Cur_Y;
- Cur_X = Line_X % 80; Cur_Y = MAX_Y2 + Line_X / 80;
- if ( ReWrt_flg == ERR )
- ReWrt_flg = TRUE;
- }
- if ( kbhit() != 0 )
- ch = Get_key(&ec);
- else
- ec = 0xFFFF;
- if ( Line_flg != FALSE ) {
- Cur_X = Bk_X; Cur_Y = Bk_Y;
- }
- if ( ec == 0xFFFF )
- break;
- else if ( ec == 0x6600 )
- ef = TRUE;
- else if ( ec == 0x6500 )
- ef = ERR;
- else if ( ec == 0x5D00 )
- Set_RSB_mode(1,2);
- else if ( ec == 0x5E00 ) {
- Line_flg = (Line_flg == FALSE ? TRUE : FALSE);
- if ( Line_flg == FALSE )
- Line_X = 1;
- Line_edit(0xFFFF);
- } else if ( ec == 0x5F00 )
- Auto_log();
- else if ( ec == 0x6100 ) {
- #ifdef TOWNS
- CD_menu();
- #endif
- Dsp_vram(cvram);
- } else if ( ec == 0x6200 )
- Down_load();
- else if ( ec == 0x6300 )
- Up_load();
- else if ( ec == 0x6400 )
- RSB_break(port,brktime[brk]);
- else if ( ch != 0xFFFF )
- Line_edit(ch);
- }
- }
- Con_end();
- if ( Down_flg != FALSE )
- Down_load();
- if ( ef == ERR )
- RSB_end();
- else
- wrtstr("通信",10,0,0x1F);
- Dsp_PFKEY();
-
- Line_flg = FALSE; Line_X = 1;
- Line_edit(0xFFFF);
-
- wrtstr(SPCSTR,30,1,0x1F);
- }